#include <iostream>

using namespace std;

const int N = 1e6 + 10;
int ne[N], pre[N];
int h;
bool set[N];



int main()
{
	int n;
	cin >> n;
	//初始化
	pre[1] = h;
	ne[h] = 1;


	// 处理 2 - N行
	for (int i = 2; i <= n; i++)
	{
		int k, p; cin >> k >> p;
		if (p == 0) // k 左边插入
		{
			ne[i] = k;
			pre[i] = pre[k];
			ne[pre[k]] = i;
			pre[k] = i;
		}
		else // k 右边插入
		{
			pre[i] = k;
			ne[i] = ne[k];
			pre[ne[k]] = i;
			ne[k] = i;
		}
	}

	int m; cin >> m;
	while (m--)
	{
		int x; cin >> x;
		if (set[x] == true) continue;
		ne[pre[x]] = ne[x];
		pre[ne[x]] = pre[x];
		set[x] = true;
	}

	// 输出结果
	for (int i = ne[h]; i; i = ne[i]) cout << i << " ";
	
	return 0;
}

